package practice1_100;

import java.util.ArrayList;
import java.util.Arrays;

public class Practice897 {
    public TreeNode increasingBST(TreeNode root) {
        ArrayList<TreeNode> list=new ArrayList<>();
        addTreeNode(root,list);
        TreeNode head=new TreeNode(0);
        TreeNode temp=head;
        for (int i = 0; i < list.size(); i++) {
            temp.left=null;
            temp.right=list.get(i);
            temp=temp.right;
        }
        temp.left=null;
        temp.right=null;
        return head.right;
    }
    private  void addTreeNode(TreeNode root, ArrayList<TreeNode> list){
        if(root==null) return ;
        //midVisit
        addTreeNode(root.left,list);
        list.add(root);
        addTreeNode(root.right,list);
    }

    public static void main(String[] args) {
        //[5,3,6,2,4,null,8,1,null,null,null,7,9]
        //[2,1,4,null,null,3]
       TreeNode root= new Practice897().increasingBST(new TreeNode(5,new TreeNode(3),new TreeNode(6,new TreeNode(8),null)));
        System.out.println(root);
    }
}
